$(document).ready(function () {

    //省初始化
    getProvinceList();
    //showUserInfo();


});
function getProvinceList() {
    $("#sel_city").html("<option value=\"0\" selected>选择城市</option>");
    $("#sel_area").html("<option value=\"0\" selected>选择区域</option>");
    $.ajax({
        type: "get",
        url: "userInfo/getProvinceList.do",
        timeout: 1000,
        dataType: "json",
        cache: false,
        success: function (data) {
            var strHtml = "<option value=\"0\" selected>选择省份</option>";
            if (data.length > 1) {
                for (var i = 0; i < data.length; i++) {
                    strHtml += "<option value='" + data[i].provinceid + "'>" + data[i].province + "</option>";
                }
            }
            $("#sel_pro").html(strHtml);
        }
    });
}
//function showUserInfo() {
//    $.ajax({
//        type: 'post',
//        url: '/user/getUser.do',
//        dataType: 'json',
//        data: {},
//        success: function (data) {
//            var province = data.user.user_province;
//            var city = data.user.user_city;
//            var county = data.user.user_county;
//            if (province != undefined) {
//                $("#provice").val(province);
//                getCityList2(city, county);
//            }
//        }
//    });
//}
//function getCityList2(cid, countid) {
//    $.ajax({
//        type: "post",
//        url: "/user/getCityList.do",
//        timeout: 1000,
//        data: {pid: $.trim($("#provice").val())},
//        dataType: "json",
//        cache: false,
//        success: function (data) {
//            var strHtml = "<option value=\"0\" selected>选择城市</option>";
//            var citylist = data.clist;
//            if (citylist.length > 1) {
//                for (var i = 0; i < citylist.length; i++) {
//                    strHtml += "<option value='" + citylist[i].id + "'>" + citylist[i].name + "</option>";
//                }
//            }
//            $("#city").html(strHtml);
//            if (cid == undefined)
//                cid = 0;
//            $("#city").val(cid);
//            if (countid == undefined)
//                countid = 0;
//            getAreaList2(countid);
//        }
//    });
//
//}
//function getAreaList2(countid) {
//    $.ajax({
//        type: "post",
//        url: "/user/getAreaList.do",
//        timeout: 1000,
//        data: {cid: $.trim($("#city").val())},
//        dataType: "json",
//        cache: false,
//        success: function (data) {
//            var strHtml = "<option value=\"0\" selected>选择县区</option>";
//            var arealist = data.alist;
//            if (arealist.length > 1) {
//                for (var i = 0; i < arealist.length; i++) {
//                    strHtml += "<option value='" + arealist[i].id + "'>" + arealist[i].name + "</option>";
//                }
//            }
//            $("#county").html(strHtml);
//            $("#county").val(countid);
//        }
//    });
//}
function getCityList() {
    $("#sel_city").html("<option value=\"0\" selected>选择城市</option>");
    $("#sel_area").html("<option value=\"0\" selected>选择区域</option>");
    $.ajax({
        type: "get",
        url: "/userInfo/getCityList.do",
        timeout: 1000,
        data: {id: $.trim($("#sel_pro").val())},
        dataType: "json",
        cache: false,
        success: function (data) {
            var strHtml = "<option value=\"0\" selected>选择城市</option>";
            var citylist = data;
            if (citylist.length > 1) {
                for (var i = 0; i < citylist.length; i++) {
                    strHtml += "<option value='" + citylist[i].cityid + "'>" + citylist[i].city + "</option>";
                }
            }
            $("#sel_city").html(strHtml);
        }
    });
}
function getAreaList() {
    $.ajax({
        type: "get",
        url: "/userInfo/getAreaList.do",
        timeout: 1000,
        data: {id: $.trim($("#sel_city").val())},
        dataType: "json",
        cache: false,
        success: function (data) {
            var strHtml = "<option value=\"0\" selected>选择县区</option>";
            var arealist = data;
            if (arealist.length > 1) {
                for (var i = 0; i < arealist.length; i++) {
                    strHtml += "<option value='" + arealist[i].areaid + "'>" + arealist[i].area + "</option>";
                }
            }
            $("#sel_area").html(strHtml);
        }
    });
}